<%@ include file="/WEB-INF/views/includes.jsp" %>
<%@ include file="/WEB-INF/views/header.jsp" %>
<%@ page session="false" %>

<h1>${operation} User</h1>

<form:form commandName="user" method="POST" autocomplete="off">
	
	<fieldset>
		<legend>User Attributes</legend>
		
		<table style="width:100%;">
			<tr>
				<td style="width:150px;">University ID:</td>
				<td>
					<c:choose>
						<c:when test="${operation == 'Add'}">
							<form:input path="username" id="username" disabled="${operation=='Edit'}" />
						</c:when>
						<c:otherwise>
							<form:hidden path="username" id="username" />
							<input type="text" value="${user.username}" disabled="disabled" />
						</c:otherwise>
					</c:choose>
					<form:errors path="username" cssClass="error" />
				</td>
			</tr>
			<tr>
				<td>Name:</td>
				<td>
					<form:input path="name" id="name" />
					<form:errors path="name" cssClass="error" />
				</td>
			</tr>
		</table>
		
	
	</fieldset>

	<fieldset style="margin-top:20px;">
		<legend>Roles</legend>
		
		<%-- There HAS to be a better way to do this--%>
		<spring:bind path="user.authorities">
		<input type="checkbox" checked="checked" disabled="disabled"> Student<br/>
		<input type="checkbox" name="authorities" value="ROLE_FACULTY"<c:forEach items="${status.value}" var="s"><c:if test="${s eq 'ROLE_FACULTY'}"> checked</c:if></c:forEach> /> Faculty<br/>
		<input type="checkbox" name="authorities" value="ROLE_ADMIN"<c:forEach items="${status.value}" var="s"><c:if test="${s eq 'ROLE_ADMIN'}"> checked</c:if></c:forEach> /> Administrator
		</spring:bind> 
	
	</fieldset>
	
	
	<fieldset style="margin-top:20px;">
		<legend>Password</legend>
		<p>To update this users password, enter a password.  Otherwise, leave these fields blank.</p>
		<table style="width:100%;">
			<tr>
				<td style="width:150px;">Password:</td>
				<td>
					<form:password path="password" id="password" />
					<form:errors path="password" cssClass="error" />
				</td>
			</tr>
			<tr>
				<td style="width:150px;">Confirm:</td>
				<td>
					<input type="password" name="confirmPassword" id="confirmPassword" />
				</td>
			</tr>
		</table>	 
	</fieldset>
	
	<div style="text-align:right;">
		<input type="submit" value="Save" />
		<input type="button" value="Cancel" onclick="javascript:window.history.go(-1);" />
	</div>

</form:form>

<%@ include file="/WEB-INF/views/footer.jsp" %>